package cc.vv.btpartyjob.partymanager.delegate

import android.annotation.SuppressLint
import android.text.TextUtils
import android.view.View
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import cc.vv.baselibrary.view.LKCircleImageView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.inter.LookBigPicFileInterface
import cc.vv.btpartyjob.partymanager.view.OnlySelectedFileShowView
import cc.vv.btpartyjob.partymanager.view.QTSelectedFileShowView
import cc.vv.btpartyjob.partymanager.view.SelectedFileShowView
import cc.vv.lkimagecomponent2.LKImage
import cc.vv.lkimagecomponent2.lib.mode.ScaleMode
import cc.vv.mvp.delegate.BaseAppDelegate
import com.dawning.utiming.task.bean.FileUrlObj
import com.dawning.utiming.task.inter.SelectedOrDeleteFileInterface

/**
 * 工作签到Delegate
 * Created by Chen.qi on 2018/10/27.
 */
@SuppressLint("SetTextI18n")
class WorkInFragmentDelegate : BaseAppDelegate() {
    override fun initWidget() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.fragment_work_in
    }

    /**
     * 自定义控件设置接口
     */
    fun setSelectedFileInterface_QD(deletedSelectedImageInter: SelectedOrDeleteFileInterface) {
        getView<SelectedFileShowView>(R.id.ll_fwi_qianDaoAddPic)?.setDeletedSelectedImageInter(deletedSelectedImageInter)
    }

    /**
     * 设置数据
     */
    fun setSelectedFileObj_QD(saltedDataList: ArrayList<FileUrlObj>?) {
        getView<SelectedFileShowView>(R.id.ll_fwi_qianDaoAddPic)?.addAllSelectedFileView(saltedDataList, 3)
    }


    /**
     * 签退
     */
    fun setSelectedFileInterface_QT(deletedSelectedImageInter: SelectedOrDeleteFileInterface) {
        getView<QTSelectedFileShowView>(R.id.ll_fwi_qianTuiAddPic)?.setDeletedSelectedImageInter(deletedSelectedImageInter)
    }

    /**
     * 签退设置数据
     */
    fun setSelectedFileObj_QT(saltedDataList: ArrayList<FileUrlObj>?) {
        getView<QTSelectedFileShowView>(R.id.ll_fwi_qianTuiAddPic)?.addAllSelectedFileView(saltedDataList, 3)
    }

    /**
     * 设置头像
     */
    fun setHead(head: String?) {
        val view = getView<LKCircleImageView>(R.id.liv_fwi_head)
        LKImage.load().load(head).placeHolder(R.mipmap.icon_party_head_def).error(R.mipmap.icon_party_head_def)
                .scale(ScaleMode.CENTER_CROP).into(view)
    }

    /**
     * 设置姓名
     */
    fun setName(str: String?) {
        val viewStr = getView<TextView>(R.id.tv_fwi_name)
        viewStr?.text = str
    }

    /**
     * 设置职务
     */
    fun setPlant(str: String?) {
        val viewStr = getView<TextView>(R.id.tv_fwi_zhiwu)
        viewStr?.text = str
    }

    /**
     * 设置电话
     */
    fun setPhone(str: String?) {
        val viewStr = getView<TextView>(R.id.tv_fwi_tel)
        viewStr?.text = str
    }


    /**
     * 设置时间
     */
    fun setCurrentTime(time: String?) {
        val viewStr = getView<TextView>(R.id.tv_fwi_time)
        viewStr?.text = time
    }


    /**
     * 仅显示签到
     */
    fun onlyShowQianDao(deletedSelectedImageInter: LookBigPicFileInterface, arrayList: ArrayList<String>?) {
        val view = getView<OnlySelectedFileShowView>(R.id.ll_fwi_OnlyQianDao)
        view?.setDeletedSelectedImageInter(deletedSelectedImageInter, 0)
        view?.addAllSelectedFileView(arrayList, 3)
    }


    /**
     * 仅显示签退
     */
    fun onlyShowQianTui(deletedSelectedImageInter: LookBigPicFileInterface, arrayList: ArrayList<String>?) {
        val view = getView<OnlySelectedFileShowView>(R.id.ll_fwi_OnlyQianTui)
        view?.setDeletedSelectedImageInter(deletedSelectedImageInter, 1)
        view?.addAllSelectedFileView(arrayList, 3)
    }


    /**
     * 设置签到时间
     */
    fun setQianDaotime(time: String?) {
        val view = getView<TextView>(R.id.tv_fwi_qianDaoTime)
        if (TextUtils.isEmpty(time)) {
            view?.text = "签到时间：未签到"
        } else {
            view?.text = "签到时间：$time"
        }
    }

    /**
     * 设置签到时间
     */
    fun setQianTuitime(time: String?) {
        val view = getView<TextView>(R.id.tv_fwi_qianTuiTime)
        if (TextUtils.isEmpty(time)) {
            view?.text = "签退时间：未签到"
        } else {
            view?.text = "签退时间：$time"
        }
    }


    /**
     * 显示签到和签退逻辑
     */
    fun showViewQD(type: Int) {
        //签到
        val viewQd = getView<LinearLayout>(R.id.ll_fwi_qd)
        //签退
        val viewQt = getView<LinearLayout>(R.id.ll_fwi_qt)
        //签到按钮
        val btnQd = getView<RelativeLayout>(R.id.rl_twi_btnQd)
        //签退按钮
        val btnQt = getView<RelativeLayout>(R.id.rl_twi_btnQt)

        //签到布局
        val picQianDao = getView<SelectedFileShowView>(R.id.ll_fwi_qianDaoAddPic)
        //仅显示签到布局
        val onlyQianDao = getView<OnlySelectedFileShowView>(R.id.ll_fwi_OnlyQianDao)


        //签到布局
        val picQianTui = getView<QTSelectedFileShowView>(R.id.ll_fwi_qianTuiAddPic)
        //仅显示签到布局
        val onlyQianTui = getView<OnlySelectedFileShowView>(R.id.ll_fwi_OnlyQianTui)


        if (type == 0) {
            //当天可签到
            viewQd?.visibility = View.VISIBLE
            viewQt?.visibility = View.GONE
            btnQd?.visibility = View.VISIBLE
            btnQt?.visibility = View.GONE

            picQianDao?.visibility = View.VISIBLE
            onlyQianDao?.visibility = View.GONE
            picQianTui?.visibility = View.GONE
            onlyQianTui.visibility = View.GONE

        } else if (type == 1) {
            //当天可签退
            viewQd?.visibility = View.VISIBLE
            btnQd?.visibility = View.GONE
            viewQt?.visibility = View.VISIBLE
            btnQt?.visibility = View.VISIBLE
            picQianDao?.visibility = View.GONE
            onlyQianDao?.visibility = View.VISIBLE
            picQianTui?.visibility = View.VISIBLE
            onlyQianTui.visibility = View.GONE

        } else if (type == 2) {
            //不可操作，仅展示数据
            viewQd?.visibility = View.VISIBLE
            viewQt?.visibility = View.VISIBLE
            btnQd?.visibility = View.GONE
            btnQt?.visibility = View.GONE

            picQianDao?.visibility = View.GONE
            picQianTui?.visibility = View.GONE

            onlyQianDao?.visibility = View.VISIBLE
            onlyQianTui.visibility = View.VISIBLE
        }
    }
}